package com.example.sample.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.app.BaseActivity;
import com.example.sample.R;

import net.liteheaven.xblib.common.rom.ShellUtil;
import net.liteheaven.xblib.widget.Toast.SmartToast;
import net.liteheaven.xblib.widget.Toast.ToastFactory;

public class RootActivity extends BaseActivity {
	
	private TextView mCmdOutput;
	private View mCmdButton;
	private EditText mCmdText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_root);
		
		mCmdOutput = (TextView)findViewById(R.id.cmd_output);
		
		mCmdButton = findViewById(R.id.cmd_button);
		mCmdButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String cmd = mCmdText.getText().toString();
				if (!TextUtils.isEmpty(cmd)){					
					String [] cmds = cmd.split("\\|");
					String result = ShellUtil.execCmds(cmds);
					handleMount(result.toString());
				}
			}
		});
		mCmdText = (EditText)findViewById(R.id.cmd_text);
	}
	
	private void handleMount(String mountInfo){
		if (TextUtils.isEmpty(mountInfo)){
			SmartToast.cancelLastToast();
			ToastFactory.makeText(this, "执行失败", Toast.LENGTH_SHORT, 1).show();
		}else{
			mCmdOutput.setText(mountInfo);
		}
	}
}
